//
//  JCCGColorRefToNSStringValueTransformer.h
//  JCSDK
//
//  Created by master on 16/3/1.
//  Copyright © 2016年 AdMaster. All rights reserved.


#import "JCValueTransformers.h"

@implementation JCCGColorRefToNSStringValueTransformer

+ (Class)transformedValueClass
{
    return [NSString class];
}

- (id)transformedValue:(id)value
{
    if (value && CFGetTypeID((__bridge CFTypeRef)value) == CGColorGetTypeID()) {
        NSValueTransformer *transformer = [NSValueTransformer valueTransformerForName:@"JCUIColorToNSStringValueTransformer"];
        return [transformer transformedValue:[[UIColor alloc] initWithCGColor:(__bridge CGColorRef)value]];
    }

    return nil;
}

- (id)reverseTransformedValue:(id)value
{
    NSValueTransformer *transformer = [NSValueTransformer valueTransformerForName:@"JCUIColorToNSStringValueTransformer"];
    UIColor *uiColor =  [transformer reverseTransformedValue:value];
    return CFBridgingRelease(CGColorCreateCopy([uiColor CGColor]));
}

@end
